package or;

import org.junit.jupiter.api.Test;

public class T1028 {
    public int equalSubstring(String s, String t, int maxCost) {
        int len = s.length();
        int[] sums = new int[len + 1];
        for (int i = 0; i < len; i++) {
            sums[i + 1] = sums[i] + Math.abs(t.charAt(i) - s.charAt(i));
        }
        int max=0;
        int left = 0;
        int right = 0;
        for (; left < len; left++) {
            while (right < len && sums[right + 1] - sums[left] <= maxCost) {
                right++;
            }
            max=Math.max(right-left,max);
        }
        return max;
    }
    @Test
    public void test() {

        System.out.println(equalSubstring("abcd","bcde",3));
    }
}
